//
//  BEOrderDetailController.swift
//  BEGlobalOiler
//
//  Created by KKING on 16/9/6.
//  Copyright © 2016年 Bullseye Energy pte ltd. All rights reserved.
//

import UIKit


class BEOrderDetailController: UIViewController {
        
    var orderModel: BEMyOrdersViewModel?
    
    @IBOutlet weak var orderStatu: UILabel!
    @IBOutlet weak var orderSn: UILabel!
    @IBOutlet weak var rigName: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        orderStatu.text = orderModel!.orderStatusName
        orderSn.text = orderModel!.orderSn
        rigName.text = orderModel!.rigName
    }
    
    @IBAction func confirmBtnDidClick(sender: UIButton) {
        let orderId = orderModel!.orderId!
        JFProgressHUD.showWithStatus(status: "Confirming orders...")
        BENetworkTools.shareNetworkTool.confirmOrder(orderId: orderId) { (success, result, error) in
            guard let resultjson = result else {
                JFProgressHUD.showWithStatus(status: "Network fault!")
                return
            }
            if resultjson["success"] == true {
                JFProgressHUD.showSuccessWithStatus(status: "Order confirmation success!")
            } else {
                JFProgressHUD.showInfoWithStatus(status: resultjson["message"].stringValue)
            }
        }
    }
    
    @IBAction func departBtnDidClick(sender: UIButton) {
        let orderId = orderModel!.orderId!
        JFProgressHUD.showWithStatus(status: "waiting submit...")
        BENetworkTools.shareNetworkTool.talentDepart(orderId: orderId) { (success, result, error) in
            guard let resultjson = result else {
                JFProgressHUD.showWithStatus(status: "Network fault!")
                return
            }
            if resultjson["success"] == true {
                JFProgressHUD.showSuccessWithStatus(status: "swbmit succsee!")
            } else {
                JFProgressHUD.showInfoWithStatus(status: resultjson["message"].stringValue)
            }
        }
    }
    
    @IBAction func repairingBtnDidClick(sender: UIButton) {
        let orderId = orderModel!.orderId!
        JFProgressHUD.showWithStatus(status: "waiting submit...")
        BENetworkTools.shareNetworkTool.talentRepairing(orderId: orderId) { (success, result, error) in
            guard let resultjson = result else {
                JFProgressHUD.showWithStatus(status: "Network fault!")
                return
            }
            if resultjson["success"] == true {
                JFProgressHUD.showSuccessWithStatus(status: "swbmit succsee!")
            } else {
                JFProgressHUD.showInfoWithStatus(status: resultjson["message"].stringValue)
            }
        }
    }
    
    @IBAction func repairedBtnDidClick(sender: UIButton) {
        let orderId = orderModel!.orderId!
        JFProgressHUD.showWithStatus(status: "waiting submit...")
        BENetworkTools.shareNetworkTool.talentRepaired(orderId: orderId) { (success, result, error) in
            guard let resultjson = result else {
                JFProgressHUD.showWithStatus(status: "Network fault!")
                return
            }
            if resultjson["success"] == true {
                JFProgressHUD.showSuccessWithStatus(status: "swbmit succsee!")
            } else {
                JFProgressHUD.showInfoWithStatus(status: resultjson["message"].stringValue)
            }
        }
    }
    
    @IBAction func preparingPackage(sender: UIButton) {
        let orderId = orderModel!.orderId!
        JFProgressHUD.showWithStatus(status: "waiting submit...")
        BENetworkTools.shareNetworkTool.preparingPackage(orderId: orderId) { (success, result, error) in
            guard let resultjson = result else {
                JFProgressHUD.showWithStatus(status: "Network fault!")
                return
            }
            if resultjson["success"] == true {
                JFProgressHUD.showSuccessWithStatus(status: "swbmit succsee!")
            } else {
                JFProgressHUD.showInfoWithStatus(status: resultjson["message"].stringValue)
            }
        }
    }
    
    @IBAction func packageUploaded(sender: UIButton) {
        let orderId = orderModel!.orderId!
        JFProgressHUD.showWithStatus(status: "waiting submit...")
        BENetworkTools.shareNetworkTool.packageUploaded(orderId: orderId) { (success, result, error) in
            guard let resultjson = result else {
                JFProgressHUD.showWithStatus(status: "Network fault!")
                return
            }
            if resultjson["success"] == true {
                JFProgressHUD.showSuccessWithStatus(status: "submit succsee!")
            } else {
                JFProgressHUD.showInfoWithStatus(status: resultjson["message"].stringValue)
            }
        }
    }
    
    @IBAction func expenseUploaded(sender: UIButton) {
        let orderId = orderModel!.orderId!
        JFProgressHUD.showWithStatus(status: "waiting submit...")
        BENetworkTools.shareNetworkTool.expenseUploaded(orderId: orderId) { (success, result, error) in
            guard let resultjson = result else {
                JFProgressHUD.showWithStatus(status: "Network fault!")
                return
            }
            if resultjson["success"] == true {
                JFProgressHUD.showSuccessWithStatus(status: "swbmit succsee!")
            } else {
                JFProgressHUD.showInfoWithStatus(status: resultjson["message"].stringValue)
            }
        }
    }
    
    
}
